﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ShredTheLog.Api.DataContracts.TextChat
{
    public abstract class SysMessage : IUserInfo
    {
        [XmlAttribute("UID")]
        public int Uid { get; set; }

        [XmlAttribute("V")]
        public string MessageText { get; set; }

        [XmlIgnore]
        public RequestAnswer? Answer
        {
            get 
            {
                switch (MessageText)
                {
                    case "Ok": return RequestAnswer.Accept;
                    case "No": return RequestAnswer.Decline;
                    default: return null;
                }
            }
            set 
            {
                if (value.HasValue)
                {
                    switch (value.Value)
                    {
                        case RequestAnswer.Accept: MessageText = "Ok"; break;
                        case RequestAnswer.Decline: MessageText = "No"; break;
                        default: throw new NotSupportedException();
                    }
                }
                else
                    MessageText = null;
            }
        }
    }

    public enum RequestAnswer
    {
        Accept,
        Decline
    }
}
